package com.lgc.demo.scheduletest;

import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;


public class TestScheduledThreadPoolExecutor {
    public static void main(String[] args) {
//        ScheduledExecutorService service = Executors.newScheduledThreadPool(2);
        ScheduledThreadPoolExecutor scheduled=new ScheduledThreadPoolExecutor(2);
        scheduled.scheduleAtFixedRate(new Runnable() {
            @Override
            public void run() {
                System.out.println("time:");
            }
        }, 0, 4000, TimeUnit.MILLISECONDS);//0表示首次执行任务的延迟时间，40表示每次执行任务的间隔时间，TimeUnit.MILLISECONDS执行的时间间隔数值单位

        TestRunnable testRunnable = new TestRunnable();
        scheduled.scheduleAtFixedRate(testRunnable, 0, 4000, TimeUnit.MILLISECONDS);//0表示首次执行
    }
}
